package com.portal.sso.jdbc.service;

import cn.hutool.core.util.StrUtil;
import com.portal.sso.core.server.PasswordEncodeServer;
import com.portal.sso.core.server.PortalUserServer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * @program: portal-sso
 * @description: jdbc的server
 * @author: xuduo
 * @create: 2021-04-27 20:24
 * @Version: 1.0
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PortalSsoJdbcServer implements PortalUserServer {
    JdbcTemplate jdbcTemplate;
    PortalSsoJdbcProperties portalSsoJdbcProperties;
    PasswordEncodeServer passwordEncodeServer;
    @Override
    public boolean Verification(String userId, String pwd) {
        try {
            String pwd_db = jdbcTemplate.queryForObject(portalSsoJdbcProperties.getSql(),String.class,userId);
            if(StrUtil.isNotEmpty(pwd_db)){
                return passwordEncodeServer.PwdEncode(pwd).equals(pwd_db);
            }
        }catch (Exception e){

        }

       return false;
    }
}
